package boot3.service.impl;

import boot3.mapper.ApplicationMapper;
import boot3.pojo.Application;
import boot3.service.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApplicationServiceImpl implements ApplicationService {
    @Autowired
    private ApplicationMapper applicationMapper;
    @Override
    public List<Application> selectAllApplication() {
        return applicationMapper.selectAllApplication();
    }

    @Override
    public List<Application> selectApplicationByStudentId(String student_id) {
        return applicationMapper.selectApplicationByStudentId(student_id);
    }

    @Override
    public List<Application> selectApplicationByProjectId(String project_id) {
        return applicationMapper.selectApplicationByProjectId(project_id);
    }

    @Override
    public Boolean updateApplicationState(String application_id) {
        return applicationMapper.updateApplicationState(application_id);
    }

    @Override
    public Boolean addApplication(Application application) {
        //首先获取所有的申请
        List<Application> applications = selectAllApplication();
        int projectapplyId = applications.get(applications.size() - 1).getProjectapply_id();
        application.setProjectapply_id(projectapplyId+1);
        application.setApply_state("申请中");
        return applicationMapper.addApplication(application);
    }
}
